package PresentationLayer;

/**
 *
 * @author Group 6
 */
public class ServiceWindow extends javax.swing.JFrame {

    View parentView = null;
    String courseId = null;
    
    /**
     * Creates new form CourseWindow with ability to get back to 
     */
    public ServiceWindow(View v) {
        initComponents();
        parentView = v;
    }
    
    /**
     * This is the constructor for doing edits on a Course
     * @param v
     * @param courseId 
     */
    public ServiceWindow(View v, String courseId){
        initComponents();
        parentView = v;
        this.courseId = courseId;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        yearField = new javax.swing.JTextField();
        courseNumberField = new javax.swing.JTextField();
        courseNameField = new javax.swing.JTextField();
        facultyPane = new javax.swing.JScrollPane();
        facultyList = new javax.swing.JList();
        submitService = new javax.swing.JButton();
        cancelWindow = new javax.swing.JButton();
        yearLabel = new javax.swing.JLabel();
        courseNumberLabel = new javax.swing.JLabel();
        courseNameLabel = new javax.swing.JLabel();
        facultyMemberLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setResizable(false);

        yearField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                yearFieldActionPerformed(evt);
            }
        });

        courseNumberField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                courseNumberFieldActionPerformed(evt);
            }
        });

        facultyList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        facultyPane.setViewportView(facultyList);

        submitService.setText("Submit");
        submitService.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                submitServiceMouseClicked(evt);
            }
        });

        cancelWindow.setText("Cancel");
        cancelWindow.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cancelWindowMouseClicked(evt);
            }
        });

        yearLabel.setText("Year");

        courseNumberLabel.setText("Course Number");

        courseNameLabel.setText("Course Name");

        facultyMemberLabel.setText("Faculty Member");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(facultyPane, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(facultyMemberLabel))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(courseNumberLabel)
                            .addComponent(yearLabel)
                            .addComponent(courseNameLabel))
                        .addGap(4, 4, 4)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(courseNameField)
                            .addComponent(courseNumberField, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(yearField, javax.swing.GroupLayout.Alignment.LEADING))
                        .addGap(44, 44, 44))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(cancelWindow)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 147, Short.MAX_VALUE)
                        .addComponent(submitService)
                        .addGap(18, 18, 18))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(yearField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(yearLabel)
                    .addComponent(facultyMemberLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(courseNumberField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(courseNumberLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(courseNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(courseNameLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(submitService)
                            .addComponent(cancelWindow)))
                    .addComponent(facultyPane))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void yearFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yearFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_yearFieldActionPerformed

    private void courseNumberFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_courseNumberFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_courseNumberFieldActionPerformed

    /**
     * Submits a new/edited Service
     * @param evt 
     */
    private void submitServiceMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_submitServiceMouseClicked
        //To Do
        //Do database insertions
        //If successful, update parent view's table
        this.setVisible(false);
        parentView.setEnabled(true);
        //If not, pop a message out
    }//GEN-LAST:event_submitServiceMouseClicked

    /**
     * Cancels 
     * @param evt 
     */
    private void cancelWindowMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cancelWindowMouseClicked
        //The user wanted to cancel out of the operation?  Easy.
        this.setVisible(false);
        parentView.setEnabled(true);
    }//GEN-LAST:event_cancelWindowMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancelWindow;
    private javax.swing.JTextField courseNameField;
    private javax.swing.JLabel courseNameLabel;
    private javax.swing.JTextField courseNumberField;
    private javax.swing.JLabel courseNumberLabel;
    private javax.swing.JList facultyList;
    private javax.swing.JLabel facultyMemberLabel;
    private javax.swing.JScrollPane facultyPane;
    private javax.swing.JButton submitService;
    private javax.swing.JTextField yearField;
    private javax.swing.JLabel yearLabel;
    // End of variables declaration//GEN-END:variables
}
